//
//  LZMusicEmptyView.m
//  laziz_Merchant
//
//  Created by ZhaoDongBo on 2016/12/7.
//  Copyright © 2016年 XBN. All rights reserved.
//

#import "LZMusicEmptyView.h"
#import "Masonry.h"

@implementation LZMusicEmptyView

- (id)init
{
    self = [super init];
    if (self) {
        [self initialize];
    }
    return self;
}

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self initialize];
    }
    return self;
}

- (id)initWithCoder:(NSCoder *)aDecoder
{
    self = [super initWithCoder:aDecoder];
    if (self) {
        [self initialize];
    }
    return self;
}

- (void)initialize {
    
    [self configView];
    
    [self addAutoLayout];
}

- (void)configView {
    
    self.backgroundColor = UIColorFromRGB(0x000000, 1);
    
    [self addSubview:self.titleLabel];
    [self addSubview:self.emptyImageView];
    [self addSubview:self.subLabel];
    [self addSubview:self.closeButton];
}

- (void)addAutoLayout {
    
    WS(weakSelf);
    GET_SCREEN_SCALE(scale);

    [self.titleLabel makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(20);
        make.leading.mas_equalTo(0);
        make.trailing.mas_equalTo(0);
        make.height.mas_equalTo(44);
    }];
    
    [self.emptyImageView makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(weakSelf.centerY).with.offset(-67);
        make.size.mas_equalTo(CGSizeMake(68, 67));
        make.centerX.mas_equalTo(weakSelf.centerX);
    }];
    
    [self.subLabel makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(weakSelf.emptyImageView.mas_bottom).with.offset(10);
        make.leading.mas_equalTo(0);
        make.trailing.mas_equalTo(0);
        make.height.mas_equalTo(30);
    }];
    
    [self.closeButton makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(-95*scale);
        make.centerX.mas_equalTo(weakSelf.centerX);
        make.size.mas_equalTo(CGSizeMake(86.5, 86.5));
    }];
}

- (void)closeButton:(id)sender {
    if (self.closeButtonActionBlock) {
        self.closeButtonActionBlock(sender);
    }
}

- (void)showView
{
    [[UIApplication sharedApplication].keyWindow addSubview:self];
    
    WS(weakSelf);
    
    [UIView animateWithDuration:0.35 animations:^{
        
        weakSelf.alpha = 0.9f;
        
        CGRect frame    = weakSelf.frame;
        frame.origin.y  = 0;
        weakSelf.frame = frame;
        
    } completion:^(BOOL finished) {
        
    }];
}

- (void)hideView
{
    WS(weakSelf);
    
    [UIView animateWithDuration:0.35 animations:^{
        
        weakSelf.alpha = 0.0f;
        
        CGRect frame    = weakSelf.frame;
        frame.origin.y  = SCREEN_HEIGHT;
        weakSelf.frame = frame;
        
    } completion:^(BOOL finished) {
        
        [self removeFromSuperview];
    }];
}


- (UILabel *)titleLabel {

    if (_titleLabel == nil) {
        _titleLabel = [[UILabel alloc] init];
        _titleLabel.text = @"Audio list";
        _titleLabel.font = [UIFont systemFontOfSize:18];
        _titleLabel.textColor = UIColorFromRGB(0xffffff, 1);
        _titleLabel.textAlignment = NSTextAlignmentCenter;
    }
    
    return _titleLabel;
}

- (UIImageView *)emptyImageView {

    if (_emptyImageView == nil) {
        _emptyImageView = [[UIImageView alloc] init];
        _emptyImageView.image = [UIImage imageNamed:@"lz_musiclist_empty"];
    }
    
    return _emptyImageView;
}

- (UILabel *)subLabel {

    if (_subLabel == nil) {
        _subLabel = [[UILabel alloc] init];
        _subLabel.text = @"Your music library is empty";
        _subLabel.textAlignment = NSTextAlignmentCenter;
        _subLabel.textColor = UIColorFromRGB(0xcccccc, 1);
        _subLabel.font = [UIFont systemFontOfSize:15];
    }
    
    return _subLabel;
}

- (UIButton *)closeButton {

    if (_closeButton == nil) {
        _closeButton = [[UIButton alloc] init];
        [_closeButton setImage:[UIImage imageNamed:@"lz_musicempty_close"] forState:UIControlStateNormal];
        [_closeButton addTarget:self action:@selector(closeButton:) forControlEvents:UIControlEventTouchUpInside];
    }
    
    return _closeButton;
}

@end
